/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Author: Huawei OS Kernel Lab
 * Create: Thu Aug 15 16:14:23 2023
 */

#ifndef __ASM_IRQFLAGS_H
#define __ASM_IRQFLAGS_H

#ifdef __KERNEL__

#include <asm/ptrace.h>

#ifdef CONFIG_CPU_V7M
#define IRQMASK_I_BIT 1
#else
#define IRQMASK_I_BIT PSR_I_BIT
#endif

static inline unsigned long arch_local_irq_save(void)
{
	return liblinux_pal_local_irq_save() ? IRQMASK_I_BIT : 0;
}

static inline void arch_local_irq_enable(void)
{
	liblinux_pal_local_irq_enable();
}

static inline void arch_local_irq_disable(void)
{
	liblinux_pal_local_irq_disable();
}

static inline unsigned long arch_local_save_flags(void)
{
	return liblinux_pal_local_save_flags() ? IRQMASK_I_BIT : 0;
}

static inline void arch_local_irq_restore(unsigned long flags)
{
	liblinux_pal_local_irq_restore((flags & IRQMASK_I_BIT) == IRQMASK_I_BIT);
}

static inline int arch_irqs_disabled_flags(unsigned long flags)
{
	return flags & IRQMASK_I_BIT;
}

static inline int arch_irqs_disabled(void)
{
	return arch_irqs_disabled_flags(arch_local_save_flags());
}

#endif /* __KERNEL__ */

#endif /* __ASM_IRQFLAGS_H */
